package com.jishuo.nontax.bfc.service;

import com.jishuo.base.service.SequenceService;
import com.jishuo.nontax.bean.message.*;
import com.jishuo.nontax.bean.vo.CheckDataListDetailVO;
import com.jishuo.nontax.bean.vo.NumAmtVO;
import com.jishuo.nontax.bean.vo.PreerrVO;
import com.jishuo.nontax.bfc.dao.*;
import com.jishuo.nontax.bfc.tlq.MessageService;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author :hanlipeng
 * @description :
 * @create :2022-12-21 13:59:00
 */
@Service
public class BankCheckService {
    private static Logger logger = LoggerFactory.getLogger(BankCheckService.class);
    
    @Resource
    private ChargeBillService chargeBillService;
    @Resource
    private BankCheckMapper bankCheckMapper;
    @Resource
    private ChargeBillMapper chargeBillMapper;
    @Resource
    private BackBillMapper backBillMapper;
    @Resource
    private BackBillService backBillService;
    @Resource
    private FiscMapper fiscMapper;
    @Resource
    private FiscService fiscService;
    @Resource
    private SpecialMapper specialMapper;
    @Resource
    private SpecialService specialService;
    @Resource
    private DivideMapper divideMapper;
    @Resource
    private DivideService divideService;
    @Resource
    private PunishService punishService;
    @Resource
    private EticketNumMapper eticketNumMapper;
    @Resource
    private EticketNumService eticketNumService;
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private StudentService studentService;
    @Resource
    private SequenceService sequenceService;
    @Resource
    private BankMapper bankMapper;
    @Resource
    private MessageService messageService;
    @Resource
    private BankPayBillMapper bankPayBillMapper;
    @Resource
    private IllegalactivityinfoMapper illegalactivityinfoMapper;
    @Resource
    private PayScaleBillMapper payScaleBillMapper;
    @Resource
    private PunishMapper punishMapper;
    @Resource
    private BankCheckBillMapper bankCheckBillMapper;
    @Resource
    private WaitaffirmMapper waitaffirmMapper;
    @Resource
    private BankposMapper bankposMapper;
    @Resource
    private DeductMapper deductMapper;
    @Resource
    private TransInfoMapper transInfoMapper;


    public void getCheckData(long bankid, String paybankdt) {

        try {
            long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");

            //发送到财政
            messageService.sendMessage("GETCHECKDATA", messageid, "<bill><bankid>" + bankid + "</bankid><paybankdt>" + paybankdt + "</paybankdt></bill>", "2.0");

        } catch (Exception e) {
            logger.info("处理获取缴款书失败：" + e.toString());
        }
    }

    public int getcheckdatacount(String accountcode, String paybankdt) {

        try {
            long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");
            long bankid = bankMapper.findBankId(accountcode);

            //发送到财政
            messageService.sendMessage("GETCHECKDATACOUNT", messageid, "<bill><bankid>" + bankid + "</bankid><paybankdt>" + paybankdt + "</paybankdt></bill>", "2.4");

            return 1;
        } catch (Exception e) {
            logger.info("处理获取获取财政端接收业务办理情况失败：" + e.toString());
            return 0;
        }
    }


    public SetCheckDataAcountDetailDTO getDataAcountDetail(GetCheckDataAcount acount, int type) {
        int num1 = 0;
        BigDecimal fund1 = new BigDecimal(0.00);
        int num2 = 0;
        BigDecimal fund2 = new BigDecimal(0.00);
        int num5 = 0;
        BigDecimal fund5 = new BigDecimal(0.00);
        int num6 = 0;
        BigDecimal fund6 = new BigDecimal(0.00);
        int num7 = 0;
        BigDecimal fund7 = new BigDecimal(0.00);
        int num9 = 0;
        BigDecimal fund9 = new BigDecimal(0.00);
        int num10 = 0;
        BigDecimal fund10 = new BigDecimal(0.00);
        int num11 = 0;
        BigDecimal fund11 = new BigDecimal(0.00);
        int num12 = 0;
        BigDecimal fund12 = new BigDecimal(0.00);
        int num13 = 0;
        BigDecimal fund13 = new BigDecimal(0.00);
        int num14 = 0;
        BigDecimal fund14 = new BigDecimal(0.00);
        int num10_1 = 0;
        BigDecimal fund10_1 = new BigDecimal(0.00);
        int num17 = 0;
        BigDecimal fund17 = new BigDecimal(0.00);
        String returnstr = "";
        if (type == 1) {
            //缴款书
            returnstr = this.findchargebill1(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num1 = Integer.parseInt(returnstr.split("&&")[0]);
                fund1 = new BigDecimal(returnstr.split("&&")[1]);
            }

            SetCheckDataAcountDetailDTO dto1 = new SetCheckDataAcountDetailDTO();
            dto1.setAmt(fund1.toString());
            dto1.setBankid(acount.getBankid());
            dto1.setDatacount(Integer.toString(num1));
            dto1.setPaybankdt(acount.getPaybankdt());
            dto1.setPurpose("1");
            return dto1;
        }
        if (type == 2) {
            //退付
            returnstr = this.findbackpaybill2(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num2 = Integer.parseInt(returnstr.split("&&")[0]);
                fund2 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto2 = new SetCheckDataAcountDetailDTO();
            dto2.setAmt(fund2.toString());
            dto2.setBankid(acount.getBankid());
            dto2.setDatacount(Integer.toString(num2));
            dto2.setPaybankdt(acount.getPaybankdt());
            dto2.setPurpose("2");
            return dto2;
        }
        if (type == 5) {
            //国库
            returnstr = this.findfisc5(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num5 = Integer.parseInt(returnstr.split("&&")[0]);
                fund5 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto5 = new SetCheckDataAcountDetailDTO();
            dto5.setAmt(fund5.toString());
            dto5.setBankid(acount.getBankid());
            dto5.setDatacount(Integer.toString(num5));
            dto5.setPaybankdt(acount.getPaybankdt());
            dto5.setPurpose("5");
            return dto5;
        }
        if (type == 6) {
            //专户
            returnstr = this.findspecial6(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num6 = Integer.parseInt(returnstr.split("&&")[0]);
                fund6 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto6 = new SetCheckDataAcountDetailDTO();
            dto6.setAmt(fund6.toString());
            dto6.setBankid(acount.getBankid());
            dto6.setDatacount(Integer.toString(num6));
            dto6.setPaybankdt(acount.getPaybankdt());
            dto6.setPurpose("6");
            return dto6;
        }
        if (type == 7) {
            //分成
            returnstr = this.finddivide7(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num7 = Integer.parseInt(returnstr.split("&&")[0]);
                fund7 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto7 = new SetCheckDataAcountDetailDTO();
            dto7.setAmt(fund7.toString());
            dto7.setBankid(acount.getBankid());
            dto7.setDatacount(Integer.toString(num7));
            dto7.setPaybankdt(acount.getPaybankdt());
            dto7.setPurpose("7");
            return dto7;
        }
        if (type == 9) {
            //高校
            returnstr = this.findstudent9(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num9 = Integer.parseInt(returnstr.split("&&")[0]);
                fund9 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto9 = new SetCheckDataAcountDetailDTO();
            dto9.setAmt(fund9.toString());
            dto9.setBankid(acount.getBankid());
            dto9.setDatacount(Integer.toString(num9));
            dto9.setPaybankdt(acount.getPaybankdt());
            dto9.setPurpose("9");
            return dto9;
        }
        if (type == 10) {
            //交管（未分成）
            returnstr = this.findillnoksnoscale10(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num10 = Integer.parseInt(returnstr.split("&&")[0]);
                fund10 = new BigDecimal(returnstr.split("&&")[1]);
            }
            //交管（已分成）
            returnstr = this.findillnoksscaledown10(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                fund10_1 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto10 = new SetCheckDataAcountDetailDTO();
            dto10.setAmt(fund10.add(fund10_1).toString());
            dto10.setBankid(acount.getBankid());
            dto10.setDatacount(Integer.toString(num10));
            dto10.setPaybankdt(acount.getPaybankdt());
            dto10.setPurpose("10");
            return dto10;
        }
        if (type == 11) {
            //交管二八汇总
            if (bankCheckMapper.findCantonidByBankID(Integer.parseInt(acount.getBankid())) == 41) {
                returnstr = this.findillnoksscaleup11(acount.getPaybankdt());
                if (returnstr.split("&&").length > 1) {
                    num11 = Integer.parseInt(returnstr.split("&&")[0]);
                    fund11 = new BigDecimal(returnstr.split("&&")[1]);
                }
                SetCheckDataAcountDetailDTO dto11 = new SetCheckDataAcountDetailDTO();
                dto11.setAmt(fund11.toString());
                dto11.setBankid(acount.getBankid());
                dto11.setDatacount(Integer.toString(num11));
                dto11.setPaybankdt(acount.getPaybankdt());
                dto11.setPurpose("11");
                return dto11;
            }
            return null;
        }
        if (type == 12) {

            //交管二八分成
            returnstr = this.findillscalebill12(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num12 = Integer.parseInt(returnstr.split("&&")[0]);
                fund12 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto12 = new SetCheckDataAcountDetailDTO();
            dto12.setAmt(fund12.toString());
            dto12.setBankid(acount.getBankid());
            dto12.setDatacount(Integer.toString(num12));
            dto12.setPaybankdt(acount.getPaybankdt());
            dto12.setPurpose("12");
            return dto12;
        }
        if (type == 13) {
            //通用罚没
            returnstr = this.findpunish13(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num13 = Integer.parseInt(returnstr.split("&&")[0]);
                fund13 = new BigDecimal(returnstr.split("&&")[1]);
            }

            SetCheckDataAcountDetailDTO dto13 = new SetCheckDataAcountDetailDTO();
            dto13.setAmt(fund13.toString());
            dto13.setBankid(acount.getBankid());
            dto13.setDatacount(Integer.toString(num13));
            dto13.setPaybankdt(acount.getPaybankdt());
            dto13.setPurpose("13");
            return dto13;
        }
        if (type == 14) {
            //网银
            returnstr = this.findwebpay14(Long.valueOf(acount.getBankid()), acount.getPaybankdt());
            if (returnstr.split("&&").length > 1) {
                num14 = Integer.parseInt(returnstr.split("&&")[0]);
                fund14 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto14 = new SetCheckDataAcountDetailDTO();
            dto14.setAmt(fund14.toString());
            dto14.setBankid(acount.getBankid());
            dto14.setDatacount(Integer.toString(num14));
            dto14.setPaybankdt(acount.getPaybankdt());
            dto14.setPurpose("14");
            return dto14;
        }
        if (type == 17) {
            //电子缴款
            returnstr = this.findbankcheck17(Long.valueOf(acount.getBankid()), acount.getPaybankdt());  //201810新增
            if (returnstr.split("&&").length > 1) {
                num17 = Integer.parseInt(returnstr.split("&&")[0]);
                fund17 = new BigDecimal(returnstr.split("&&")[1]);
            }
            SetCheckDataAcountDetailDTO dto17 = new SetCheckDataAcountDetailDTO();
            dto17.setAmt(fund17.toString());
            dto17.setBankid(acount.getBankid());
            dto17.setDatacount(Integer.toString(num17));
            dto17.setPaybankdt(acount.getPaybankdt());
            dto17.setPurpose("17");
            return dto17;
        }
        return null;

    }

    public String findbackpaybill2(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findbackpaybill2(bankid, paybankdt);
        return listString(funds);
    }

    public String findchargebill1(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findchargebill1(bankid, paybankdt);
        return listString(funds);
    }

    public String findfisc5(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findfisc5(bankid, paybankdt);
        return listString(funds);
    }

    public String findspecial6(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findspecial6(bankid, paybankdt);
        return listString(funds);
    }

    public String finddivide7(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.finddivide7(bankid, paybankdt);
        return listString(funds);
    }

    public String findstudent9(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findstudent9(bankid, paybankdt);
        return listString(funds);
    }


    public String findillnoksscaledown10(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findillnoksscaledown10(bankid, paybankdt);
        return listString(funds);
    }

    public String findillnoksnoscale10(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findillnoksnoscale10(bankid, paybankdt);
        return listString(funds);
    }

    public String findillnoksscaleup11(String paybankdt) {
        List<String> funds = bankCheckMapper.findillnoksscaleup11(paybankdt);
        return listString(funds);
    }

    public String findillscalebill12(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findillscalebill12(bankid, paybankdt);
        return listString(funds);
    }

    public String findpunish13(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findpunish13(bankid, paybankdt);
        return listString(funds);
    }

    public String findwebpay14(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findwebpay14(bankid, paybankdt);
        return listString(funds);
    }

    public String findbankcheck17(Long bankid, String paybankdt) {
        List<String> funds = bankCheckMapper.findbankcheck17(bankid, paybankdt);
        return listString(funds);
    }


    public String listString(List<String> funds) {
        if (funds != null && funds.size() > 0) {
            return funds.get(0);
        } else {
            return "0";
        }
    }

    public List<SetCheckDataListDetailDTO> findSendCheckDataListDetailDTO(Long bankid, String paybankdt, String ptype) {
        try {
            List<CheckDataListDetailVO> list = new ArrayList<>();
            if ("1".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO1(bankid, paybankdt);
            } else if ("2".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO2(bankid, paybankdt);
            } else if ("3".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO3(bankid, paybankdt);
            } else if ("4".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO4(bankid, paybankdt);
            } else if ("5".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO5(bankid, paybankdt);
            } else if ("6".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO6(bankid, paybankdt);
            } else if ("7".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO7(bankid, paybankdt);
            } else if ("8".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO8(bankid, paybankdt);
            } else if ("9".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO9(bankid, paybankdt);
            } else if ("10".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO10(bankid, paybankdt);
            } else if ("11".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO11(bankid, paybankdt);
            } else if ("12".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO12(bankid, paybankdt);
            } else if ("13".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO13(bankid, paybankdt);
            } else if ("14".equals(ptype)) {

            } else if ("15".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO15(bankid, paybankdt);
            } else if ("16".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO16(bankid, paybankdt);
            } else if ("17".equals(ptype)) {
                list = bankCheckMapper.findSendCheckDataListDetailDTO17(bankid, paybankdt);
            }


            ArrayList<SetCheckDataListDetailDTO> detailDtos = new ArrayList<>();
            for (CheckDataListDetailVO checkDataListDetailVO : list) {
                detailDtos.add(checkDataListDetailVO.getSetCheckDataListDetailDTO());

            }
            return detailDtos;
        } catch (Exception e) {
            logger.info("失败" + e.toString());
            return null;
        }
    }

    public ArrayList<SetCheckDataListDetailDTO> getCZQ(ArrayList<SetCheckDataListDetailDTO> list, ArrayList<SetCheckDataListDetailDTO> list1) {

        for (SetCheckDataListDetailDTO b : list) {
            for (SetCheckDataListDetailDTO a : list1) {
                if (b.getAmt().equals(a.getAmt()) && b.getBankaffirm().equals(a.getBankaffirm()) && b.getBillnum().equals(a.getBillnum())) {
                    list1.remove(a);
                    break;
                }
            }
        }
        return list1;
    }

    @Resource
    private PreerrMapper preerrMapper;

    public void sysSETPREERR(String data){
        //xml解析器
        Serializer serializer = new Persister();
        try{
            //区划信息对象
            SetPreerr preerr = serializer.read(SetPreerr.class, new StringReader(data));
            if(preerr!=null && preerr.getPreerr()!=null && preerr.getPreerr().size()>0){
                for(SetPreerrDTO dto:preerr.getPreerr()){
                    PreerrVO preerrVO = new PreerrVO(dto);
                    if(dto!=null && dto.getPaybankdt()!=null && !dto.getPaybankdt().trim().equals("") && dto.getBankid()!=null && !dto.getBankid().trim().equals("")){
                        preerrMapper.deleteBankIdPayBank(preerrVO);
                        preerrMapper.savePreerr(preerrVO);
                        break;
                    }
                }
            }
        }catch(Exception e){
            logger.info("分析处理预审结果失败"+e.toString());
        }
    }

    public void sysSETPREERRDETAIL(String data){
        //xml解析器
        Serializer serializer = new Persister();
        try{
            //区划信息对象
            SetPreerrDetail detail = serializer.read(SetPreerrDetail.class, new StringReader(data));
            if(detail!=null&&detail.getDetail()!=null&&detail.getDetail().size()>0){
                List<SetPreerrDetailDTO> detail1 = detail.getDetail();
                PreerrVO preerrVO = new PreerrVO(detail1.get(0));
                preerrMapper.deletePreeDetailBankId(preerrVO);

                List<PreerrVO> preerrVOS = new ArrayList<>();
                for (SetPreerrDetailDTO setPreerrDetailDTO : detail1) {
                    preerrVOS.add(new PreerrVO(setPreerrDetailDTO));
                }
                if(preerrVOS.size()>0){
                    preerrMapper.insertPreerrdetail(preerrVOS);
                }

            }
        }catch(Exception e){
            logger.info("分析处理预审结果失败"+e.toString());
        }
    }

    public void sendCHECKDATACOUNT(String data){

        //xml解析器
        Serializer serializer = new Persister();
        try {
            GetCheckDataAcount acount = serializer.read(GetCheckDataAcount.class, new StringReader(data));
            ArrayList<SetCheckDataAcountDetailDTO> list =getSetCheckDataAcountDetail(acount);

            if(list!=null && list.size()>0){
                long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");
                SetCheckDataAcount bankcheck = new SetCheckDataAcount();
                bankcheck.setPreerr(list);
                //发送到财政
                messageService.sendMessage("SETCHECKDATACOUNT", messageid, bankcheck, "2.0");
            }
        } catch (Exception e) {
            logger.info("处理失败："+e.toString());

        }
    }

    public ArrayList<SetCheckDataAcountDetailDTO> getSetCheckDataAcountDetail(GetCheckDataAcount acount)
    {
        int num1 =0;BigDecimal fund1=new BigDecimal(0.00);
        int num2 =0;BigDecimal fund2=new BigDecimal(0.00);
        int num5 =0;BigDecimal fund5=new BigDecimal(0.00);
        int num6 =0;BigDecimal fund6=new BigDecimal(0.00);
        int num7 =0;BigDecimal fund7=new BigDecimal(0.00);
        int num9 =0;BigDecimal fund9=new BigDecimal(0.00);
        int num10 =0;BigDecimal fund10=new BigDecimal(0.00);
        int num11 =0;BigDecimal fund11=new BigDecimal(0.00);
        int num12 =0;BigDecimal fund12=new BigDecimal(0.00);
        int num13 =0;BigDecimal fund13=new BigDecimal(0.00);
        int num14 =0;BigDecimal fund14=new BigDecimal(0.00);
        int num10_1 =0;BigDecimal fund10_1=new BigDecimal(0.00);
        int num17 =0;BigDecimal fund17=new BigDecimal(0.00);
        ArrayList<SetCheckDataAcountDetailDTO> list = new ArrayList<>();

        //缴款书
        NumAmtVO numAmtVO = chargeBillMapper.selectCharBillNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO!=null){
            num1=numAmtVO.getNum();
            fund1=numAmtVO.getAmt();
        }

        SetCheckDataAcountDetailDTO dto1=new SetCheckDataAcountDetailDTO();
        dto1.setAmt(fund1+"");
        dto1.setBankid(acount.getBankid());
        dto1.setDatacount(num1+"");
        dto1.setPaybankdt( acount.getPaybankdt());
        dto1.setPurpose(1+"");
        list.add(dto1);

        //退付
        NumAmtVO numAmtVO1 = bankPayBillMapper.selectPayBillNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO1!=null){
            num2=numAmtVO1.getNum();
            fund2=numAmtVO1.getAmt();
        }
        SetCheckDataAcountDetailDTO dto2=new SetCheckDataAcountDetailDTO();
        dto2.setAmt(fund2+"");
        dto2.setBankid(acount.getBankid());
        dto2.setDatacount(num2+"");
        dto2.setPaybankdt( acount.getPaybankdt());
        dto2.setPurpose(2+"");
        list.add(dto2);


        //国库
        NumAmtVO numAmtVO2 = fiscMapper.selectFiscNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO2!=null){
            num5=numAmtVO2.getNum();
            fund5=numAmtVO2.getAmt();
        }
        SetCheckDataAcountDetailDTO dto5=new SetCheckDataAcountDetailDTO();
        dto5.setAmt(fund5+"");
        dto5.setBankid(acount.getBankid());
        dto5.setDatacount(num5+"");
        dto5.setPaybankdt( acount.getPaybankdt());
        dto5.setPurpose(5+"");
        list.add(dto5);
        //专户
        NumAmtVO numAmtVO3 = specialMapper.selectSpecialNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO3!=null){
            num6=numAmtVO3.getNum();
            fund6=numAmtVO3.getAmt();
        }
        SetCheckDataAcountDetailDTO dto6=new SetCheckDataAcountDetailDTO();
        dto6.setAmt(fund6+"");
        dto6.setBankid(acount.getBankid());
        dto6.setDatacount(num6+"");
        dto6.setPaybankdt( acount.getPaybankdt());
        dto6.setPurpose(6+"");
        list.add(dto6);
        //分成
        NumAmtVO numAmtVO4 = divideMapper.selectDivideNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO4!=null){
            num7=numAmtVO4.getNum();
            fund7=numAmtVO4.getAmt();
        }
        SetCheckDataAcountDetailDTO dto7=new SetCheckDataAcountDetailDTO();
        dto7.setAmt(fund7+"");
        dto7.setBankid(acount.getBankid());
        dto7.setDatacount(num7+"");
        dto7.setPaybankdt( acount.getPaybankdt());
        dto7.setPurpose(7+"");
        list.add(dto7);

        //高校
        NumAmtVO numAmtVO5 = studentMapper.selectStudentNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO5!=null){
            num9=numAmtVO5.getNum();
            fund9=numAmtVO5.getAmt();
        }
        SetCheckDataAcountDetailDTO dto9=new SetCheckDataAcountDetailDTO();
        dto9.setAmt(fund9+"");
        dto9.setBankid(acount.getBankid());
        dto9.setDatacount(num9+"");
        dto9.setPaybankdt( acount.getPaybankdt());
        dto9.setPurpose(9+"");
        list.add(dto9);
        //交管（未分成）
        NumAmtVO numAmtVO6 = illegalactivityinfoMapper.selectActiviInfoNumAmtOne(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO6!=null){
            num10=numAmtVO6.getNum();
            fund10=numAmtVO6.getAmt();
        }
        //交管（已分成）
        NumAmtVO numAmtVO7 =illegalactivityinfoMapper.selectActiviInfoNumAmtTwo(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO7!=null){
            num10_1=numAmtVO7.getNum();
            fund10_1=numAmtVO7.getAmt();
        }
        SetCheckDataAcountDetailDTO dto10=new SetCheckDataAcountDetailDTO();
        dto10.setAmt(fund10.add(fund10_1)+"");
        dto10.setBankid(acount.getBankid());
        dto10.setDatacount(num10+"");
        dto10.setPaybankdt( acount.getPaybankdt());
        dto10.setPurpose(10+"");
        list.add(dto10);

        //交管二八汇总
        if(bankCheckMapper.findCantonidByBankID(Integer.parseInt(acount.getBankid()))==41){
            NumAmtVO numAmtVO8 = illegalactivityinfoMapper.selectActiviInfoNumAmtThree(acount.getPaybankdt());
            if(numAmtVO8!=null){
                num11=numAmtVO8.getNum();
                fund11=numAmtVO8.getAmt();
            }
            SetCheckDataAcountDetailDTO dto11=new SetCheckDataAcountDetailDTO();
            dto11.setAmt(fund11+"");
            dto11.setBankid(acount.getBankid());
            dto11.setDatacount(num11+"");
            dto11.setPaybankdt( acount.getPaybankdt());
            dto11.setPurpose(11+"");
            list.add(dto11);
        }



        //交管二八分成
        NumAmtVO numAmtVO8 = payScaleBillMapper.selectScaleBillNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO8!=null){
            num12=numAmtVO8.getNum();
            fund12=numAmtVO8.getAmt();
        }
        SetCheckDataAcountDetailDTO dto12=new SetCheckDataAcountDetailDTO();
        dto12.setAmt(fund12+"");
        dto12.setBankid(acount.getBankid());
        dto12.setDatacount(num12+"");
        dto12.setPaybankdt( acount.getPaybankdt());
        dto12.setPurpose(12+"");
        list.add(dto12);

        //通用罚没
        NumAmtVO numAmtVO9 = punishMapper.selectPunisInfoNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO9!=null){
            num13=numAmtVO9.getNum();
            fund13=numAmtVO9.getAmt();
        }

        SetCheckDataAcountDetailDTO dto13=new SetCheckDataAcountDetailDTO();
        dto13.setAmt(fund13+"");
        dto13.setBankid(acount.getBankid());
        dto13.setDatacount(num13+"");
        dto13.setPaybankdt( acount.getPaybankdt());
        dto13.setPurpose(13+"");
        list.add(dto13);


        //网银
        NumAmtVO numAmtVO10 = bankCheckBillMapper.selectCheckBillNumAmt(acount.getBankid(), acount.getPaybankdt());
        if(numAmtVO10!=null){
            num14=numAmtVO10.getNum();
            fund14=numAmtVO10.getAmt();
        }
        SetCheckDataAcountDetailDTO dto14=new SetCheckDataAcountDetailDTO();
        dto14.setAmt(fund14+"");
        dto14.setBankid(acount.getBankid());
        dto14.setDatacount(num14+"");
        dto14.setPaybankdt( acount.getPaybankdt());
        dto14.setPurpose(14+"");
        list.add(dto14);


        //电子缴款
        NumAmtVO numAmtVO11 = eticketNumMapper.selectEtickNumAmt(acount.getBankid(), acount.getPaybankdt());//201810新增
        if(numAmtVO11!=null){
            num17=numAmtVO11.getNum();
            fund17=numAmtVO11.getAmt();
        }
        SetCheckDataAcountDetailDTO dto17=new SetCheckDataAcountDetailDTO();
        dto17.setAmt(fund17+"");
        dto17.setBankid(acount.getBankid());
        dto17.setDatacount(num17+"");
        dto17.setPaybankdt( acount.getPaybankdt());
        dto17.setPurpose(17+"");
        list.add(dto17);

        return list;
    }

    public void sendCHECKDATALIST(String data){
        //xml解析器
        Serializer serializer = new Persister();
        //xml转换器
        StringWriter sw = new StringWriter();
        try {
            GetCheckDataAcountList acount = serializer.read(GetCheckDataAcountList.class, new StringReader(data));
            ArrayList<SetCheckDataListDetailDTO> list = (ArrayList<SetCheckDataListDetailDTO>)findSendCheckDataListDetailDTO(Long.valueOf(acount.getBankid()),acount.getPaybankdt(),acount.getPurpose());
            if(list!=null && list.size()>0){
                long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");
                SetCheckDataList bankcheck = new SetCheckDataList();
                bankcheck.setPreerr(list);
                //发送到财政
                messageService.sendMessage("SETCHECKDATALIST", messageid, bankcheck, "2.0");
            }
        } catch (Exception e) {
            logger.info("处理失败："+e.toString());

        }

    }

/*
    public void setCheckData(String data,String billstate){
        //xml解析器
        Serializer serializer = new Persister();
        try{
            SetCheckData checkdata = serializer.read(SetCheckData.class, new StringReader(data));
            String accountcode="";
            if(checkdata!=null && checkdata.getData()!=null && checkdata.getData().size()>0){
                for(SetCheckDataDTO dto:checkdata.getData()){
                    if(dto!=null && dto.getPaybankdt()!=null && !dto.getPaybankdt().trim().equals("") && dto.getBankid()!=null && !dto.getBankid().trim().equals("")){
                        if(accountcode.equals("")){
                            accountcode = bankMapper.findBankByBankid(Long.valueOf(dto.getBankid())).get(0).getAccountcode();
                        }
                        if(this.saveCheckData(dto,billstate,accountcode)<=0){
                            break;
                        }
                    }
                }
            }
        }catch(Exception e){
            logger.info("分析处理预审结果失败"+e.toString());
        }
    }
    public int saveCheckData(SetCheckDataDTO dto,String info,String accountcode){
        try{
            if(info!=null && info.trim().equals("1")){
                chargeBillMapper.deleteChargebillfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                chargeBillMapper.saveChargebillfiance(new CheckDataVO(dto));
            }else if(info!=null && info.trim().equals("2")){

                backBillMapper.deleteBackpaybillfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                backBillMapper.saveBackpaybillfiance(new CheckDataVO(dto));
            }else if(info!=null && info.trim().equals("3")){
                waitaffirmMapper.deleteWaitaffirmfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                waitaffirmMapper.saveWaitaffirmfiance(new CheckDataVO(dto));

            }else if(info!=null && info.trim().equals("4")){
                bankposMapper.deleteBankposfiance(dto.getBankaffirm(),accountcode,dto.getPaybankdt().substring(0,10));
                CheckDataVO checkDataVO = new CheckDataVO(dto);
                checkDataVO.setAccountcode(accountcode);
                checkDataVO.setPaybankdt(dto.getPaybankdt().substring(0,10));
                bankposMapper.saveBankposfiance(checkDataVO);

            }else if(info!=null && info.trim().equals("5")){

                fiscMapper.deletePayfiscfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                fiscMapper.savePayfiscfiance(new CheckDataVO(dto));
            }else if(info!=null && info.trim().equals("6")){
                specialMapper.deletePayspecialfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                specialMapper.insertPayspecialfiance(new CheckDataVO(dto));

            }else if(info!=null && info.trim().equals("7")){
                divideMapper.deletePaydividefiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                divideMapper.savePaydividefiance(new CheckDataVO(dto));
            }else if(info!=null && info.trim().equals("8")){

                deductMapper.deleteDeductfiance(dto.getBankaffirm(),accountcode,dto.getPaybankdt().substring(0,10));
                CheckDataVO checkDataVO = new CheckDataVO(dto);
                checkDataVO.setAccountcode(accountcode);
                deductMapper.saveDeductfiance(checkDataVO);
            }else if(info!=null && info.trim().equals("9")){
                studentMapper.deleteStudentfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                studentMapper.saveStudentfiance(new CheckDataVO(dto));

            }else if(info!=null && info.trim().equals("10")){
                illegalactivityinfoMapper.deleteIllegalactivityinfofiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());

                CheckDataVO checkDataVO = new CheckDataVO(dto);
                checkDataVO.setFunds(new BigDecimal(dto.getFunds().split(",")[0]));
                checkDataVO.setLatefee(new BigDecimal(dto.getFunds().split(",")[1]));
                illegalactivityinfoMapper.saveIllegalactivityinfofiance(checkDataVO);

            }else if(info!=null && info.trim().equals("12")){
                payScaleBillMapper.deletePayscalebillfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());

                CheckDataVO checkDataVO = new CheckDataVO(dto);
                checkDataVO.setBillnum(dto.getBillnum().split(",")[0]);
                checkDataVO.setBillno(dto.getBillnum().split(",")[1]);
                payScaleBillMapper.savePayscalebillfiance(checkDataVO);

            }else if(info!=null && info.trim().equals("13")){
                punishMapper.deletePunishfiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                punishMapper.savePunishfiance(new CheckDataVO(dto));
            }else if(info!=null && info.trim().equals("14")){
                transInfoMapper.deleteTransinfofiance(dto.getBankid(),dto.getPaybankdt(),dto.getBankaffirm());
                transInfoMapper.saveTransinfofiance(new CheckDataVO(dto));
            }
            return 1;
        }catch(Exception e){
            logger.info("保存预审结果失败"+e.toString());
            return 0;
        }
    }
*/
}
